/*  ****************************************************************
 *  ConfigFile.h
 *  CheeseBurgerParadise
 *
 *  Config file parser
 * *****************************************************************
 */

#ifndef _CB_CONFIG_FILE_H__
#define _CB_CONFIG_FILE_H__

#include <ogre.h>
#include <fstream>
#include <string>
#include <list>

using namespace std;
using namespace Ogre;

class CharacterConfig;
class BandConfigFile;


typedef list<CharacterConfig> CharacterList;

class BandConfigFile
{
public:

	static bool openConfigFile(const char * configFile);
	static bool openDefaultConfigFile();
	static string getDefaultConfigFile();
	static string getMocapPath() { return mocapPath; }
	static string getModelsPath() { return modelsPath; }
	
	static bool reload();
	
	static bool parse();
	
	static const CharacterList & getCharacters() { 
		return allCharacters;
	}
	
	static bool hasSoundtrack() { return soundtrackFile.length() > 0; }
	static const string & getSoundtrackFile() { return soundtrackFile; }
	static bool loadBandEnabled() { return loadBand; }
private:

	static ifstream input;
	static CharacterList allCharacters;
	
	// soundtrack file
	static string soundtrackFile;
	static bool loadBand;
	static string mocapPath;
	static string modelsPath;
	
};


class CharacterConfig
{
public:
	CharacterConfig(
		string	name,
		string	mesh,
		string	vsk,
		string	v,
		string map,
		const Vector3 & cOffset,
		float dT):
		
		characterName(name),
		meshFile(mesh),
		vskFile(vsk),
		vFile(v),
		mapFile(map),
		offset(cOffset),
		deltaTime(dT),
		instrumentOffset(0, 0, 0) {}
	
	const string & getName() const { return characterName; }
	string getMeshFile() const { return BandConfigFile::getModelsPath() + meshFile; }
	string getVSKFile() const { return BandConfigFile::getMocapPath() + vskFile; }
	string getVFile() const { return BandConfigFile::getMocapPath() + vFile; }
	string getMapFile() const { return BandConfigFile::getMocapPath() + mapFile; }
	const Vector3 & getOffset() const { return offset; }
	float getDeltaTime() const { return deltaTime; }
	
	const Vector3 & getInstrumentOffset() const { return instrumentOffset; }
	string getInstrumentV() const { return BandConfigFile::getMocapPath() + instrumentV; }
	string getInstrumentVSK() const { return BandConfigFile::getMocapPath() + instrumentVSK; }
	string getInstrumentMesh() const { return BandConfigFile::getModelsPath() + instrumentMesh; }
	string getInstrumentMap() const { return BandConfigFile::getMocapPath() + instrumentMap; }
	
	bool hasInstrument() const {
		return (instrumentV.length() > 0 && instrumentVSK.length() > 0 && instrumentMesh.length() > 0 && instrumentMap.length() > 0 );
	}
	
	void setInstrumentOffset(Vector3 & offset) { instrumentOffset = offset; }
	void setInstrumentV(string v) { instrumentV = v; }
	void setInstrumentVSK(string vsk) { instrumentVSK = vsk; }
	void setInstrumentMesh(string mesh) { instrumentMesh = mesh; }
	void setInstrumentMap(string map) { instrumentMap = map; }
	
private:
	
	string		characterName;
	string		meshFile;
	string		vskFile;
	string		vFile;
	string		mapFile;
	
	string		instrumentV;
	string		instrumentVSK;
	string		instrumentMesh;
	string		instrumentMap;
	
	Vector3		offset;
	Vector3		instrumentOffset;
	
	float		deltaTime;
};

// checks whether argument string is whitespace only
bool isWhite(const string & str);

// parser offset and returns ogre vector
Vector3 readOffsetVector(const string & data, bool & status);

float readFloat(const string & data);

// prints out entries in band configuration file (for debugging)
void printBandConfig();

#endif

